package entity

import (
	"context"
	"time"

	"github.com/LyricTian/gin-admin/v7/internal/app/schema"
	"github.com/LyricTian/gin-admin/v7/pkg/util/structure"
	"github.com/jinzhu/gorm"
)

// GetGroupNotificationDB 获取group_notification存储
func GetGroupNotificationDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
	return GetDBWithModel(ctx, defDB, new(GroupNotification))
}

// SchemaGroupNotification group_notification对象
type SchemaGroupNotification schema.GroupNotification

// ToGroupNotification 转换为group_notification实体
func (a SchemaGroupNotification) ToGroupNotification() *GroupNotification {
	item := new(GroupNotification)
	structure.Copy(a, item)
	return item
}

// GroupNotification group_notification实体
type GroupNotification struct {
	ID            string     `gorm:"column:id;primary_key;size:36;"`
	GroupId       string     `gorm:"size:36;column:group_id;"`        // 群ID
	ContentId     string     `gorm:"size:36;column:content_id;"`      // 内容ID,点赞时关联语音视频内容ID
	NotifyImage   string     `gorm:"column:notify_image;size:256;"`   // 通知内容图片
	NotifyContent string     `gorm:"size:256;column:notify_content;"` // 通知内容
	Type          int        `gorm:"column:type;size:11;"`            // 类型(1:私发消息 2:群发消息 3:语音点赞 4:视频点赞 5:语音收藏 6:视频收藏)
	Creator       string     `gorm:"size:36;index;column:creator;"`   // 创建者
	CreatedAt     time.Time  `gorm:"column:created_at;index;"`
	UpdatedAt     time.Time  `gorm:"column:updated_at;index;"`
	DeletedAt     *time.Time `gorm:"column:deleted_at;index;"`
}

// ToSchemaGroupNotification 转换为group_notification对象
func (a GroupNotification) ToSchemaGroupNotification() *schema.GroupNotification {
	item := new(schema.GroupNotification)
	structure.Copy(a, item)
	return item
}

// GroupNotifications group_notification列表
type GroupNotifications []*GroupNotification

// ToSchemaGroupNotifications 转换为group_notification对象列表
func (a GroupNotifications) ToSchemaGroupNotifications() []*schema.GroupNotification {
	list := make([]*schema.GroupNotification, len(a))
	for i, item := range a {
		list[i] = item.ToSchemaGroupNotification()
	}
	return list
}
